/*
	PC审批表格字段
*/
import {
	approvalStateLable,
	confirmStateLabel,
	flowStepLabel,
	isDiscardLabel
} from "./copyPc";
import divideByHundred from "./divideByHundred"
import {
	forMatStringToObject
} from "./format";

/*
 * type: false 待审批 / true: 已审批
 */
// 1 采购订单
// 2 销售订单
export const columnsPendingApproval = (type) => [{
		title: "合同编号",
		dataIndex: "contractNumber",
	},
	{
		title: "供方公司",
		dataIndex: "supplyCompany",
	},
	{
		title: "需方公司",
		dataIndex: "requireCompany",
	},
	{
		title: "商品名称",
		dataIndex: "commodity",
	},
	{
		title: "单价",
		dataIndex: "price",
		formatter: {
			type: "text",
			format: (row) => {
				return {
					value: divideByHundred(row.price),
					color: "primary",
				};
			},
		},
	},
	{
		title: "吨位",
		dataIndex: "tonnage",
	},
	{
		title: "总金额",
		dataIndex: "totalMoney",
		formatter: {
			type: "text",
			format: (row) => {
				return {
					value: divideByHundred(row.totalMoney),
					color: "primary",
				};
			},
		},
	},
	...(type ? [{
			title: "审批人",
			dataIndex: "approvalUser",
		},

		{
			title: "审批结果",
			dataIndex: "approvalState",
			formatter: {
				type: "text",
				format: (row) => {
					//  1待审批，2已通过，3已驳回，4已撤销
					return approvalStateLable[row.approvalState || "-1"];
				},
			},
		},
		{
			title: "审批日期",
			dataIndex: "approvalOpinion",
		},
	] : [{
			title: "提交人",
			dataIndex: "createdBy",
		},
		{
			title: "提交日期",
			dataIndex: "createdTime",
		},
	]),
];

// 3 取消订单
const columnsCancelOrder = (type) => [{
		title: "合同编号",
		dataIndex: "contractNumber",
	},
	{
		title: "供方公司",
		dataIndex: "supplyCompany",
	},
	{
		title: "需方公司",
		dataIndex: "requireCompany",
	},
	{
		title: "商品名称",
		dataIndex: "commodity",
	},
	{
		title: "单价",
		dataIndex: "price",
		formatter: {
			type: "text",
			format: (row) => {
				return {
					value: divideByHundred(row.price),
					color: "primary",
				};
			},
		},
	},
	{
		title: "吨位",
		dataIndex: "tonnage",
	},
	{
		title: "总金额",
		dataIndex: "totalMoney",
		formatter: {
			type: "text",
			format: (row) => {
				return {
					value: divideByHundred(row.totalMoney),
					color: "primary",
				};
			},
		},
	},
	// 新的
	{
		title: "完成数量",
		dataIndex: "finishNum",
	},
	{
		title: "完成金额",
		dataIndex: "finishMoney",
		formatter: {
			type: "text",
			format: (row) => {
				return {
					value: divideByHundred(row.finishMoney),
					color: "primary",
				};
			},
		},
	},
	{
		title: "取消数量",
		dataIndex: "cancelNUm",
	},
	{
		title: "取消金额",
		dataIndex: "cancelMoney",

		formatter: {
			type: "text",
			format: (row) => {
				return {
					value: divideByHundred(row.cancelMoney),
					color: "primary",
				};
			},
		},
	},
	// 新的结束
	{
		title: "提交人",
		dataIndex: "createdBy",
	},
	{
		title: "提交日期",
		dataIndex: "createdTime",
	},
];

// 4 物流付费
const columnsLogisticsExpenditure = (type) => [{
		title: "物流公司",
		dataIndex: "companyName",
	},
	{
		title: "报车人",
		dataIndex: "name",
		hidden: true,
	},
	{
		title: "联系方式",
		dataIndex: "phone",
		hidden: true,
	},
	{
		title: "司机",
		dataIndex: "driverName",
	},
	{
		title: "车号",
		dataIndex: "vehicleNo",
	},
	{
		title: "装车日期",
		dataIndex: "loadingTime",
	},
	{
		title: "卸车日期",
		dataIndex: "unloadDate",
	},

	{
		title: "装车地点",
		dataIndex: "loadingAddress",
	},
	{
		title: "卸车地点",
		dataIndex: "unloadAddress",
	},
	{
		title: "装车磅单",
		dataIndex: "loadingPoundAffix",
		formatter: {
			type: "image",
			format: (row) => {
				return forMatStringToObject(row.loadingPoundAffix, "装车磅单");
			},
		},
	},
	{
		title: "实际装车吨位",
		dataIndex: "loadingTonnage",
	},
	{
		title: "卸车磅单",
		dataIndex: "unloadPoundAffix",
		formatter: {
			type: "image",
			format: (row) => {
				return forMatStringToObject(row.unloadPoundAffix, "卸车磅单");
			},
		},
	},
	{
		title: "实际卸车吨位",
		dataIndex: "unloadTonnage",
	},
	{
		title: "运费单价",
		dataIndex: "freightPrice",
		formatter: {
			type: "text",
			format: (row) => {
				return {
					value: divideByHundred(row.freightPrice),
					color: "primary",
				};
			},
		},
	},

	{
		title: "总亏损吨",
		dataIndex: "lossTonnage",
		width: 250,
		formatter: {
			type: "text",
			format: (row) => {
				// 装车吨位
				const loadT = row.loadingTonnage;
				// 卸车吨位
				const unloadT = row.unloadTonnage;
				// 原最大吨位（精度问题）
				const maxTon = Math.floor(loadT * 1000 - unloadT * 1000) / 1000;
				const ton = maxTon || 0;
				return {
					value: `${ton}吨`,
					color: "primary",
				};
			},
		},
	},
	{
		title: "公司承担亏损吨",
		dataIndex: "lossSharing",
		width: 250,
		formatter: {
			type: "text",
			format: (row) => {
				const ton = row.lossSharing || 0;
				return {
					value: `${ton}吨`,
					color: "primary",
				};
			},
		},
	},
	{
		title: "亏损单价",
		dataIndex: "lossPrice",
		formatter: {
			type: "text",
			format: (row) => {
				return {
					value: divideByHundred(row.lossPrice),
					color: "primary",
				};
			},
		},
	},
	{
		title: "亏损金额",
		dataIndex: "lossAmount",
		formatter: {
			type: "text",
			format: (row) => {
				return {
					value: divideByHundred(row.lossAmount),
					color: "primary",
				};
			},
		},
	},
	//
	{
		title: "总运费",
		dataIndex: "oughtFreightAmount",
		formatter: {
			type: "text",
			format: (row) => {
				return {
					value: divideByHundred(row.oughtFreightAmount),
					color: "primary",
				};
			},
		},
	},

	{
		title: "运输状态",
		dataIndex: "true",
		hidden: true,
		formatter: {
			type: "text",
			format: (row) => {
				return approvalStateLable[row.approvalState || "-1"];
			},
		},
	},
	// 榜单状态
	{
		dataIndex: "confirmState",
		title: "榜单状态",
		formatter: {
			type: "text",
			format: (row) => {
				return confirmStateLabel[row.confirmState || "-1"];
			},
		},
	},
	// 审批状态
	{
		dataIndex: "flowStep",
		title: "审批状态",
		formatter: {
			type: "text",
			format: (row) => {
				return flowStepLabel[row.flowStep || "-1"];
			},
		},
	},
	// 订单状态
	{
		dataIndex: "isDiscard",
		title: "过磅单状态",
		formatter: {
			type: "text",
			format: (row) => {
				return isDiscardLabel[row.isDiscard || "-1"];
			},
		},
	},
];

// 5 发票
const columnsBill = (type) => [{
		title: "合同编号",
		dataIndex: "contractNumber",
	},
	{
		title: "客户",
		dataIndex: "custom",
	},
	{
		title: "收款金额",
		dataIndex: "receivables",
		formatter: {
			type: "text",
			format: (row) => {
				return {
					value: divideByHundred(row.receivables),
					color: "primary",
				};
			},
		},
	},
	{
		title: "已开票",
		dataIndex: "invoiceMoney",
		formatter: {
			type: "text",
			format: (row) => {
				return {
					value: divideByHundred(row.invoiceMoney),
					color: "primary",
				};
			},
		},
	},
	{
		title: "未开票",
		dataIndex: "unInvoiceMoney",
		formatter: {
			type: "text",
			format: (row) => {
				return {
					value: divideByHundred(row.unInvoiceMoney),
					color: "primary",
				};
			},
		},
	},
	{
		title: "申请开票金额",
		dataIndex: "invoicePrice",
		formatter: {
			type: "text",
			format: (row) => {
				return {
					value: divideByHundred(row.invoicePrice),
					color: "primary",
				};
			},
		},
	},
	...(type ? [{
			title: "审批人",
			dataIndex: "approvalUser",
		},
		{
			title: "审批结果",
			dataIndex: "approvalResult",
			formatter: {
				type: "text",
				format: (row) => {
					return approvalResultLabel[row.approvalResult || "-1"];
				},
			},
		},
		{
			title: "审批日期",
			dataIndex: "approvalTime",
		},
	] : [{
			title: "申请人",
			dataIndex: "applyName",
		},
		{
			title: "申请时间",
			dataIndex: "createdTime",
		},
	]),
];

// 6 收/付款单
const columnsPaymentOrder = (type) => [{
		title: "单据编号",
		dataIndex: "receiptNumber",
	},
	{
		title: "单据类型",
		dataIndex: "receiptType",
		formatter: {
			type: "text",
			format: (row) => {
				// 1 收款单，2 付款单
				return receiptTypeLabel[row.receiptType || "-1"];
			},
		},
	},
	{
		title: "供应商名称",
		dataIndex: "companyName",
	},
	{
		title: "付款类型",
		dataIndex: "payType",
		formatter: {
			type: "text",
			format: (row) => {
				const vdx = payType.find((v) => v.value == row.payType);
				return {
					value: vdx?.label || "--",
					color: "primary",
				};
			},
		},
	},
	{
		title: "付款账号",
		dataIndex: "payAccount",
	},
	{
		title: "付款行",
		dataIndex: "openingBank",
	},
	{
		title: "付款金额",
		dataIndex: "payMoney",
		formatter: {
			type: "text",
			format: (row) => {
				return {
					value: divideByHundred(row.payMoney),
					color: "primary",
				};
			},
		},
	},
	{
		title: "付款时间",
		dataIndex: "payDate",
	},
	...(type ? [{
			title: "审批人",
			dataIndex: "approvalUser",
		},
		{
			title: "审批状态",
			dataIndex: "approvalState",
			formatter: {
				type: "text",
				format: (row) => {
					//  1待审批，2已通过，3已驳回，4已撤销
					return approvalStateLable[row.approvalState || "-1"];
				},
			},
		},
		{
			title: "审批结果",
			dataIndex: "approvalResult",
			formatter: {
				type: "text",
				format: (row) => {
					// 1 通过 0 驳回
					return approvalResultLabel[row.approvalResult || "-1"];
				},
			},
		},
		{
			title: "审批日期",
			dataIndex: "approvalOpinion",
		},
	] : []),
];

// 7 报车人
const columnsCarReport = () => [{
		title: "物流公司名称",
		dataIndex: "company",
	},
	{
		title: "营业执照",
		dataIndex: "license",

		formatter: {
			type: "image",
			format: (row) => {
				return forMatStringToObject(row.license, "营业执照");
			},
		},
	},
	{
		title: "报车人姓名",
		dataIndex: "name",
	},
	{
		title: "身份证正面",
		dataIndex: "idcarda",
		formatter: {
			type: "image",
			format: (row) => {
				return forMatStringToObject(row.idcarda, "身份证正面");
			},
		},
	},
	{
		title: "身份证反面",
		dataIndex: "idcardb",
		formatter: {
			type: "image",
			format: (row) => {
				return forMatStringToObject(row.idcardb, "身份证反面");
			},
		},
	},
	{
		title: "报车人手机号",
		dataIndex: "phone",
	},
	{
		title: "收款人",
		dataIndex: "accountName",
	},
	{
		title: "开户行",
		dataIndex: "openingBank",
	},
	{
		title: "收款账号",
		dataIndex: "account",
	},
	{
		title: "登录账号",
		dataIndex: "loginAccount",
	},
	{
		title: "登录密码",
		dataIndex: "loginPass",
	},
	{
		title: "审批状态",
		dataIndex: "approvalState",
		formatter: {
			type: "text",
			format: (row) => {
				// 1待审批，2正常，3驳回，4禁用
				return approvalStateLable[row.approvalState || "-1"];
			},
		},
	},
	{
		title: "启用状态",
		dataIndex: "state",
		formatter: {
			type: "text",
			format: (row) => {
				// 1待审批，2正常，3驳回，4禁用
				return stateLabel[row.state || "-1"];
			},
		},
	},
];

// 8 用车需求
const columnsApproved = (type) => [{
		title: "车号",
		dataIndex: "vehicleNo",
	},
	{
		title: "挂车号",
		dataIndex: "trailerNo",
	},
	{
		title: "司机",
		dataIndex: "driverName",
	},
	{
		title: "身份证号",
		dataIndex: "driverIdcard",
	},
	{
		title: "手机号",
		dataIndex: "driverPhone",
	},
	{
		title: "押运员姓名",
		dataIndex: "pledgeName",
	},
	{
		title: "押运员身份证号",
		dataIndex: "pledgeIdcard",
	},
	{
		title: "装车吨位",
		dataIndex: "tonnage",
	},

	{
		title: "运输公司名称",
		dataIndex: "companyName",
	},
	{
		title: "驾驶证",
		dataIndex: "driverAffix",
		formatter: {
			type: "image",
			format: (row) => {
				return forMatStringToObject(row.driverAffix, "驾驶证");
			},
		},
	},
	{
		title: "行驶证",
		dataIndex: "travelAffix",
		formatter: {
			type: "image",
			format: (row) => {
				return forMatStringToObject(row.travelAffix, "行驶证");
			},
		},
	},
	{
		title: "审批结果",
		dataIndex: "approvalState",

		formatter: {
			type: "text",
			format: (row) => {
				//  1待审批，2已通过，3已驳回，4已撤销
				return approvalStateLable[row.approvalState || "-1"];
			},
		},
	},
	{
		title: "审批日期",
		dataIndex: "approvalOpinion",
	},
];

// 10 榜单审批
const columnsWeighingListConfirmation = (type) => [{
		title: "物流公司",
		dataIndex: "companyName",
	},
	{
		title: "报车人",
		dataIndex: "name",
		hidden: true,
	},
	{
		title: "联系方式",
		dataIndex: "phone",
		hidden: true,
	},
	{
		title: "司机",
		dataIndex: "driverName",
	},
	{
		title: "车号",
		dataIndex: "vehicleNo",
	},
	{
		title: "装车日期",
		dataIndex: "loadingTime",
	},
	{
		title: "卸车日期",
		dataIndex: "unloadDate",
	},

	{
		title: "装车地点",
		dataIndex: "loadingAddress",
	},
	{
		title: "卸车地点",
		dataIndex: "unloadAddress",
	},
	{
		title: "装车磅单",
		dataIndex: "loadingPoundAffix",
		formatter: {
			type: "image",
			format: (row) => {
				return forMatStringToObject(row.loadingPoundAffix, "装车磅单");
			},
		},
	},
	{
		title: "实际装车吨位",
		dataIndex: "loadingTonnage",
	},
	{
		title: "卸车磅单",
		dataIndex: "unloadPoundAffix",
		formatter: {
			type: "image",
			format: (row) => {
				return forMatStringToObject(row.unloadPoundAffix, "卸车磅单");
			},
		},
	},
	{
		title: "实际卸车吨位",
		dataIndex: "unloadTonnage",
	},
	{
		title: "运费单价",
		dataIndex: "freightPrice",
		formatter: {
			type: "text",
			format: (row) => {
				return {
					value: divideByHundred(row.freightPrice),
					color: "primary",
				};
			},
		},
	},

	{
		title: "总亏损吨",
		dataIndex: "lossTonnage",
		width: 250,
		formatter: {
			type: "text",
			format: (row) => {
				// 装车吨位
				const loadT = row.loadingTonnage;
				// 卸车吨位
				const unloadT = row.unloadTonnage;
				// 原最大吨位（精度问题）
				const maxTon = Math.floor(loadT * 1000 - unloadT * 1000) / 1000;
				const ton = maxTon || 0;
				return {
					value: `${ton}吨`,
					color: "primary",
				};
			},
		},
	},
	{
		title: "公司承担亏损吨",
		dataIndex: "lossSharing",
		width: 250,
		formatter: {
			type: "text",
			format: (row) => {
				const ton = row.lossSharing || 0;
				return {
					value: `${ton}吨`,
					color: "primary",
				};
			},
		},
	},
	{
		title: "亏损单价",
		dataIndex: "lossPrice",
		formatter: {
			type: "text",
			format: (row) => {
				return {
					value: divideByHundred(row.lossPrice),
					color: "primary",
				};
			},
		},
	},
	{
		title: "亏损金额",
		dataIndex: "lossAmount",
		formatter: {
			type: "text",
			format: (row) => {
				return {
					value: divideByHundred(row.lossAmount),
					color: "primary",
				};
			},
		},
	},
	{
		title: "总运费",
		dataIndex: "oughtFreightAmount",
		formatter: {
			type: "text",
			format: (row) => {
				return {
					value: divideByHundred(row.oughtFreightAmount),
					color: "primary",
				};
			},
		},
	},

	{
		title: "运输状态",
		dataIndex: "true",
		hidden: true,
		formatter: {
			type: "text",
			format: (row) => {
				return approvalStateLable[row.approvalState || "-1"];
			},
		},
	},
	// 榜单状态
	{
		dataIndex: "confirmState",
		title: "榜单状态",
		formatter: {
			type: "text",
			format: (row) => {
				return confirmStateLabel[row.confirmState || "-1"];
			},
		},
	},
	// 审批状态
	{
		dataIndex: "flowStep",
		title: "审批状态",
		formatter: {
			type: "text",
			format: (row) => {
				return flowStepLabel[row.flowStep || "-1"];
			},
		},
	},
	// 订单状态
	{
		dataIndex: "isDiscard",
		title: "过磅单状态",
		formatter: {
			type: "text",
			format: (row) => {
				return isDiscardLabel[row.isDiscard || "-1"];
			},
		},
	},
];

// 1. 采购订单和销售订单数据一样
export const getTableColumn = {
	1: columnsPendingApproval,
	2: columnsPendingApproval,
	3: columnsCancelOrder,
	4: columnsLogisticsExpenditure,
	5: columnsBill,
	6: columnsPaymentOrder,
	7: columnsCarReport,
	8: columnsApproved,
	10: columnsWeighingListConfirmation,
};